package br.edu.ufcg.lp2;

import static org.junit.Assert.*;

import org.junit.Before;
import org.junit.Test;

public class TagTest {
	
	Tag t1;
	Tag t2;
	Tag t3;

	@Before
	public void setUp() throws Exception {
		// Three simple tags to be used in the tests
		t1 = new Tag("biblico");
		t2 = new Tag("frances");
		t3 = new Tag("hebraico");
	}

	@Test
	public void testTag() {
		try {
			// Creating normal tag
			t1 = new Tag("italiano");
			assertEquals("italiano", t1.getName());
			
			// Creating tag with empty name, must catch exception
			t2 = new Tag("");
			fail("Did not break with empty name");
		} catch (Exception e) {
			assertEquals("Name cannot be empty", e.getMessage());
		}
	}

	@Test
	public void testGetName() throws Exception {
		// GetName test for t1, t2 and t3
		assertEquals("biblico", t1.getName());
		assertEquals("frances", t2.getName());
		assertEquals("hebraico", t3.getName());
		
		// GetName test after a set
		t1.setName("alemao");
		t2.setName("novo testamento");
		t3.setName("indigena");
		assertEquals("alemao", t1.getName());
		assertEquals("novo testamento", t2.getName());
		assertEquals("indigena", t3.getName());
	}

	@Test
	public void testSetName() {
		try {
			// Asserting t1's name before and after the set
			assertEquals("biblico", t1.getName());
			t1.setName("antigo testamento");
			assertEquals("antigo testamento", t1.getName());
			
			// Setting t2's name for an empty string, must catch exception
			assertEquals("frances", t2.getName());
			t2.setName("");
			fail("Did not break with an empty name");
		} catch (Exception e) {
			assertEquals("Name cannot be empty", e.getMessage());
		}
	}

	@Test
	public void testEquals() throws Exception {
		// Test case in which the tags are assertEquals("Tag [name = biblico]", t1.toString());the same
		t3 = new Tag("biblico");
		assertEquals(true, t1.equals(t3));
		
		// Test case in which the tags differ
		assertEquals(false, t2.equals(t3));
	}
	
	@Test
	public void testToString() {
		// Asserting toString works
		assertEquals("Tag [name = biblico]", t1.toString());
		assertEquals("Tag [name = frances]", t2.toString());
		assertEquals("Tag [name = hebraico]", t3.toString());
	}

}
